package com.cape.elasticsearch;


import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Configuration
public class MyConfig {

    @Bean
    public TransportClient client() throws UnknownHostException {

        InetSocketTransportAddress node = new InetSocketTransportAddress(
                InetAddress.getByName("localhost"),
                9300
        );
//        InetSocketTransportAddress slave1Node = new InetSocketTransportAddress(
//                InetAddress.getByName("localhost"),
//                9301
//        );
//        InetSocketTransportAddress slave2Node = new InetSocketTransportAddress(
//                InetAddress.getByName("localhost"),
//                9302
//        );

        Settings settings = Settings.builder().put("cluster.name", "mycluster")
                .build();

        TransportClient client = new PreBuiltTransportClient(settings);
        client.addTransportAddress(node);
//        client.addTransportAddress(slave1Node);
//        client.addTransportAddress(slave2Node);

        return client;
    }


}
